package com.forum.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.forum.pojo.vo.SearchTeacherVo;
import com.forum.result.Result;
import com.forum.service.TeacherInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName TeacherInfoController
 * @Description TODO
 * @Author suyao
 * @Version 1.0
 */
@RestController
@CrossOrigin
@RequestMapping("/teacherInfo")
@Api
public class TeacherInfoController {
    @Autowired
    private TeacherInfoService teacherInfoService;
    /**
     * 获取教师信息并分页
     * @param searchTeacherVo
     * @param currentPage
     * @param limit
     * @return
     */
    @ApiOperation("获取老师信息并分页")
    @RequestMapping(value = "/getByPage",method = RequestMethod.POST)
    public Result<Page> getTeacherInfoByPage(@RequestBody SearchTeacherVo searchTeacherVo, @RequestParam Long currentPage, @RequestParam Long limit){
        Page teacherInfoByPage = teacherInfoService.getTeacherInfoByPage(searchTeacherVo, currentPage, limit);
        return Result.ok(teacherInfoByPage);
    }

    /**
     * 修改权限
     * @param changedAdmin
     * @param teacherId
     * @return
     */
    @ApiOperation("修改权限")
    @RequestMapping(value = "/changeAdmin",method = RequestMethod.POST)
    public Result changeAdmin(@RequestParam Integer changedAdmin,@RequestParam String teacherId){
        if(teacherInfoService.changeAdmin(changedAdmin,teacherId)==1)
            return Result.ok();
        return Result.fail();
    }
    @ApiOperation("修改禁言状态")
    @RequestMapping(value = "/changeStatus",method = RequestMethod.POST)
    public Result changeStatus(@RequestParam Integer changedStatus,@RequestParam String teacherId){
        if(teacherInfoService.changeStatus(changedStatus,teacherId)==1)
            return Result.ok();
        return Result.fail();
    }
    @ApiOperation("添加老师")
    @RequestMapping(value = "addTeacher",method = RequestMethod.POST)
    public Result addTeacher(@RequestParam Long teacherId,@RequestParam String name,@RequestParam String unit,@RequestParam String occupation){
        Integer integer = teacherInfoService.addTeacher(teacherId, name, unit, occupation);
        if(integer==1)
            return Result.ok();
        return Result.fail();
    }
}
